<?php
declare(strict_types=1);

namespace App\Controller\v1;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use Hyperf\DbConnection\Db;
use App\Constants\ReturnCode;
use App\Helper\Common;
use Throwable;
use App\Service\GzhService;
use App\Helper\Util;
use App\Helper\Log;

#[Controller]
class NotifyController extends AbstractController
{
    #[Inject]
    protected GzhService $gzhServ;
    
    #用户登录
    #[RequestMapping(path: "wxevent", methods: "get,post")]
    public function wxevent(){
        $bodys = $this->request->getBody()->getContents();
        Log::get("wx_event")->info($bodys);
        $bodys = Util::xmlToArray($bodys);
        $msg_type = $bodys['MsgType']??"";
        switch ($msg_type) {
            case 'event':
                $res = $this->gzhServ->handleEvent($bodys);
                break;
            case 'text':
                $res = $this->gzhServ->handleText($bodys);
                break;
            default:
                $res = $this->request->input("echostr", NULL);
                break;
        }
        return $res;
    }
    
}